//
//  GenericGraphViewController.m
//  Balance
//
//  Created by Sophia Tsay on 6/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "GenericGraphViewController.h"

@interface GenericGraphViewController ()

@end

@implementation GenericGraphViewController
@synthesize toolbar = _toolbar;
@synthesize splitViewBarButtonItem = _splitViewBarButtonItem;
@synthesize graphView = _graphView;

- (void) setToolbar:(UIToolbar *)toolbar
{
    _toolbar = toolbar;
    self.toolbar.barStyle = UIBarStyleBlackTranslucent; 
}

- (void) setSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
    if (_splitViewBarButtonItem != splitViewBarButtonItem) {
        NSMutableArray *toolBarItems = [self.toolbar.items mutableCopy];
        if (_splitViewBarButtonItem) [toolBarItems removeObject:_splitViewBarButtonItem];
        if (splitViewBarButtonItem) [toolBarItems addObject:splitViewBarButtonItem];
        self.toolbar.items = toolBarItems;
        _splitViewBarButtonItem = splitViewBarButtonItem;        
    }
    if (self.toolbar.items.count == 0 && self.toolbar.hidden == NO)
    {
    	self.toolbar.hidden = YES;
        [self.graphView setFrame:CGRectMake(self.graphView.frame.origin.x, self.graphView.frame.origin.y - self.toolbar.frame.size.height, self.graphView.frame.size.width, self.graphView.frame.size.height + self.toolbar.frame.size.height)];
    } else if (self.toolbar.items.count != 0 && self.toolbar.hidden == YES) {
        self.toolbar.hidden = NO;
        [self.graphView setFrame:CGRectMake(self.graphView.frame.origin.x, self.graphView.frame.origin.y + self.toolbar.frame.size.height, self.graphView.frame.size.width, self.graphView.frame.size.height - self.toolbar.frame.size.height)];
    }
    
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)loadView
{
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setToolbar:nil];
    [self setGraphView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

@end
